<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('选择部门领导')"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<body class="gray-bg">
<input type="hidden" id="rowIds">
<div class="container-div">
    <div class="row">
        <!--审批人筛选条件查询-->
        <div class="col-sm-12 search-collapse">
            <p class="select-title">审批人筛选查询</p>
            <form id="ordinary-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <span style="color: red; " > *</span>审批人角色： <select id="roles" name="roleId">
                            <option value="">--请选择筛选审批人角色--</option>
                        </select>

                        </li>
                        <li>
                            <span style="color: red; " > *</span> 审批人职位：<select name="postId" id="posts">
                            <option value="">--请选择筛选审批人职位--</option>
                        </select>
                        </li>
                        <li>
                            <span style="color: red; " > *</span> 审批人部门：<select name="deptId" id="depts_parent">
                            <option value="">--请选择筛选审批人上级部门--</option>
                        </select>
                        </li>
                        <li>
                            审批人上级部门：<select name="parentId" id="depts">
                            <option value="">--请选择筛选审批人上级部门--</option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <!--审批人列表-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<th:block th:include="include :: bootstrap-select-js"/>
<th:block th:include="include :: jquery-cxselect-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/user";
    var prefix_role = ctx + "system/role";
    var prefix_post = ctx + "system/post";
    var prefix_dept = ctx + "system/dept";
    var deptId=[[${deptId}]];
    if (deptId==null){
      deptId="";
    }
    var data_roles;
    var data_posts;
    var data_depts;
    // 查询所有角色
    $.ajax({
        url: prefix_role+"/list",
        type: "post",
        dataType: "json",
        success: function (datas){
            console.log("datas",datas);
            data_roles=datas.rows;

            for (var  i = 0; i < data_roles.length; i++) {
                $('#roles').append("<option value=" + data_roles[i].roleId + ">" + data_roles[i].roleName + "</option>");

            }
            // 缺一不可
            // $('#adeName').selectpicker('refresh');
            // $('#adeName').selectpicker('render');
        }
    });

    // 查询所有岗位
    $.ajax({
        url: prefix_post+"/list",
        type: "post",
        dataType: "json",
        success: function (datas){
            console.log("datas",datas);
            data_posts=datas.rows;

            for (var  i = 0; i < data_posts.length; i++) {
                $('#posts').append("<option value=" + data_posts[i].postId + ">" + data_posts[i].postName + "</option>");

            }
            // 缺一不可
            // $('#adeName').selectpicker('refresh');
            // $('#adeName').selectpicker('render');
        }
    });

    // 查询所有部门
    $.ajax({
        url: prefix_dept+"/list",
        type: "post",
        dataType: "json",
        success: function (datas){
            console.log("datas",datas);
            data_depts=datas;

            for (var  i = 0; i < data_depts.length; i++) {
                $('#depts').append("<option value=" + data_depts[i].deptId + ">" + data_depts[i].deptName + "</option>");
                $('#depts_parent').append("<option value=" + data_depts[i].deptId + ">" + data_depts[i].deptName + "</option>");
            }

            // 缺一不可
            // $('#adeName').selectpicker('refresh');
            // $('#adeName').selectpicker('render');
        }
    });


    console.log("deptId:",deptId);
    $(function () {
        var options = {
            url: prefix + "/chooseAuditUser",
            showSearch: false,
            showRefresh: true,
            showToggle: true,
            showColumns: true,
            method: "get",
            columns: [{
                // field: 'state',
                // checkbox: true
                radio: true
            },
                {
                    field: 'userId',
                    title: '用户ID',
                    visible: false
                },
                {
                    field: 'loginName',
                    title: '登录名称',
                    sortable: true
                },
                {
                    field: 'userName',
                    title: '用户名',
                },
                {
                    field: 'dept.deptId',
                    title: '部门ID',
                    visible: false
                },
                {
                    field: 'parentId',
                    title: '上级部门ID',
                    visible: false
                },
                {
                    field: 'deptParentName',
                    title: '上级部门名称'
                },
                {
                    field: 'dept.deptName',
                    title: '用户所在部门'
                },

                {
                    field: 'postId',
                    title: '岗位ID',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'postName',
                    title: '岗位名称',
                    sortable: true
                },
                {
                    field: 'roleId',
                    title: '角色ID',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'roleName',
                    title: '角色名称',
                    sortable: true
                },
                ]
        };
        $.table.init(options);
    });


    /* 添加用户-选择用户-提交(回调形式-父页面调用子页面) */
    function getSelections() {
       var selected= $.table.selectFirstColumns();
        console.log("selected:",selected);
        return selected;
    }

    function getSelections2() {
        var selected2= $.table.selectColumns("userName");
        console.log("selected2:",selected2);
        return selected2;
    }

    $("#bootstrap-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) {
        var rows = $.common.equals("uncheck-all", e.type) ? rowsBefore : rowsAfter;
        var rowIds = $.table.affectedRowIds(rows);
        $("#rowIds").val(rowIds);
    });
</script>
</body>
</html>